package com.sky.controller.statistics;

import cn.hutool.core.date.DateUtil;
import com.sky.controller.BaseController;
import com.sky.domain.Check;
import com.sky.domain.CheckStat;
import com.sky.dto.CheckQueryDto;
import com.sky.service.CheckService;
import com.sky.vo.AjaxResult;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 检查项目统计控制器
 * @author sky
 * @create 2021-07-20 16:48
 */
@RestController
@RequestMapping("/statistics/check")
public class StatCheckItemController extends BaseController {

    @Reference
    private CheckService checkService;

    /**
     * 查询检查项列表
     */
    @GetMapping("queryCheck")
    public AjaxResult queryCheck(CheckQueryDto checkQueryDto) {
        // 没有设置查询时间，默认当天
        if (checkQueryDto.getBeginTime() == null) {
            checkQueryDto.setQueryDate(DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
        }
        List<Check> checks = this.checkService.queryCheck(checkQueryDto);
        return AjaxResult.success(checks);
    }

    /**
     * 查询检查项统计列表
     */
    @GetMapping("queryCheckStat")
    public AjaxResult queryCheckStat(CheckQueryDto checkQueryDto) {
        // 没有设置查询时间，默认当天
        if (checkQueryDto.getBeginTime() == null) {
            checkQueryDto.setQueryDate(DateUtil.format(DateUtil.date(), "yyyy-MM-dd"));
        }
        List<CheckStat> checkStats = this.checkService.queryCheckStat(checkQueryDto);
        return AjaxResult.success(checkStats);
    }
}
